package org.class2table.core.dictionary;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;

/**
 * 默认规则定义
 */
public class DefaultRule {

    public static class SqlDefaultRule {
        /**
         * 文本类的字段类型
         * 默认值需要加单引号，
         * 建表需要指定字符集。
         */
        public final static List<String> TEXT_TYPE;

        static {
            TEXT_TYPE =
                    Arrays.asList(
                            Constants.INFORMATION_SCHEMA.DATA_TYPE.VARCHAR,
                            Constants.INFORMATION_SCHEMA.DATA_TYPE.CHAR,
                            Constants.INFORMATION_SCHEMA.DATA_TYPE.TEXT,
                            Constants.INFORMATION_SCHEMA.DATA_TYPE.LONGTEXT
                    );

        }

    }

    /**
     * java类型默认对应的mysql类型
     */
    public final static Map<Class<?>, String> CLAZZ_2_COLUMN_TYPE_RULE_MAP;

    static {
        CLAZZ_2_COLUMN_TYPE_RULE_MAP = new HashMap<>();
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Byte.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.TINYINT1);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Character.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.CHAR1);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Short.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.SMALLINT);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Integer.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.INT);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Double.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.DOUBLE);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Float.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.FLOAT);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Long.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.BIGINT_UNSIGNED);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Boolean.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.TINYINT1);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(String.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.VARCHAR255);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(BigDecimal.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.DECIMAL10_0);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(Date.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.DATETIME);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(java.sql.Date.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.DATETIME);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(LocalDate.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.DATE);
        CLAZZ_2_COLUMN_TYPE_RULE_MAP.put(LocalDateTime.class, Constants.INFORMATION_SCHEMA.DEFAULT_COLUMN_TYPE.DATETIME);
    }

    /**
     * mysql类型默认对应的java类型
     */
    public final static Map<String, Class<?>> DATA_TYPE_2_CLAZZ_RULE_MAP;

    static {
        DATA_TYPE_2_CLAZZ_RULE_MAP = new HashMap<>();
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.TINYINT, Boolean.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.CHAR, Character.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.SMALLINT, Short.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.INT, Integer.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.DOUBLE, Double.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.FLOAT, Float.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.BIGINT_UNSIGNED, Long.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.BIGINT, Long.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.VARCHAR, String.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.DECIMAL, BigDecimal.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.DATE, LocalDate.class);
        DATA_TYPE_2_CLAZZ_RULE_MAP.put(Constants.INFORMATION_SCHEMA.DATA_TYPE.DATETIME, LocalDateTime.class);
    }

}